//
//  BillMapViewController.m
//  dangdang
//
//  Created by air on 16/3/8.
//  Copyright © 2016年 luweijie. All rights reserved.
//

#import "BillMapViewController.h"
#import <AMapNaviKit/MAMapKit.h>
#import <AMapNaviKit/AMapNaviKit.h>

@interface BillMapViewController ()<MAMapViewDelegate>

{
    MAMapView * _mapView;
}

@property (nonatomic, strong) AMapNaviPoint* expressPoint;

@end

@implementation BillMapViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"查看地图";
}

- (void) viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [self initNaviPoint];
    
    [self configMapView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)initNaviPoint
{
    NSLog(@"lng = %@, lat = %@", userObject.lng, userObject.lat);
    CGFloat lng = [userObject.lng floatValue];
    CGFloat lat = [userObject.lat floatValue];
    _expressPoint = [AMapNaviPoint locationWithLatitude:lat longitude:lng];
}

- (void)configMapView
{
    _mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, 64, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds))];
    _mapView.delegate = self;
    _mapView.userTrackingMode = 1;
    _mapView.customizeUserLocationAccuracyCircleRepresentation = YES;
    
    [_mapView setZoomLevel:16.1 animated:YES];
    
    MAPointAnnotation *pointAnnotation = [[MAPointAnnotation alloc] init];
    pointAnnotation.coordinate = CLLocationCoordinate2DMake(_expressPoint.latitude, _expressPoint.longitude);
    [_mapView setCenterCoordinate:pointAnnotation.coordinate];
    [_mapView selectAnnotation:pointAnnotation animated:YES];
    [_mapView addAnnotation:pointAnnotation];
    
    [self.view addSubview:_mapView];
}

- (MAOverlayView *)mapView:(MAMapView *)mapView viewForOverlay:(id <MAOverlay>)overlay{
    return nil;
}

// 修改大头针图片
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation
{
    static NSString *reuseIndetifier = @"annotationReuseIndetifier";
    MAAnnotationView *annotationView = (MAAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier];
    if (annotationView == nil)
    {
        annotationView = [[MAAnnotationView alloc] initWithAnnotation:annotation
                                                      reuseIdentifier:reuseIndetifier];
    }
    annotationView.image = [UIImage imageNamed:@"hk_address2.png"];
    //设置中心点偏移，使得标注底部中间点成为经纬度对应点
    annotationView.centerOffset = CGPointMake(0, -18);
    return annotationView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
